package demo.test.handler;

import com.just_bean.JustBeanApplication;
import com.just_bean.core.handler.AnnoHandler;
import demo.test.anno.DI;

import java.lang.reflect.Field;

public class DIHandler extends AnnoHandler<DI> {
    private JustBeanApplication justBeanApplication;

    public void setJustBeanApplication(JustBeanApplication justBeanApplication) {
        this.justBeanApplication = justBeanApplication;
    }

    @Override
    public Object field(Class<?> clz, Field field, DI annotation) throws Exception {
        String diName = annotation.name();
        String name = "".equals(diName) ? field.getName() : diName;
        return justBeanApplication.get(field.getType(), name);
    }
}
